package com.softdev.repo;

import com.softdev.pojo.Module;
import com.softdev.pojo.Project;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Set;

public interface ProjectRepository extends JpaRepository<Project , Long> {

    Project findByName(String name);

    @EntityGraph(attributePaths = {"skills" , "risks" , "modules"})
    @Query("SELECT p FROM Project p WHERE p.id = :projectId")
    Project findByIdWithLazyProperties(@Param("projectId") Long projectId);

    @EntityGraph(attributePaths = {"skills" , "risks" , "modules"})
    @Query("SELECT p FROM Project p")
    List<Project> findAllWithLazyProperties();

    @Query("SELECT p.modules FROM Project p WHERE p.id = :projectId")
    Set<Module> findModules(@Param("projectId") Long projectId);

}
